﻿using System;

using Optimization.Utilities;

namespace Optimization.StandardProblems
{

    [IsProblem]
    public class Ackley : IProblem
    {
        int dim = 2;

        public Ackley()
        {
            this.dim = 2;
        }

        static public double Evaluate(Vector v)
        {
            double X = v[0];
            double Y = v[1];
            double result = Math.Exp(-0.3) * Math.Sqrt(X * X + Y * Y) + 3 * (Math.Cos(2 * X) + Math.Sin(2 * Y));

            return result;
        }

        double IProblem.Evaluate(Vector v)
        {
            return Evaluate(v);
        }

        void IProblem.GetBounds(out Vector mins, out Vector maxs)
        {
            mins = -30 * Vector.One(dim);
            maxs = +30 * Vector.One(dim);
        }

        bool IProblem.IsFeasible(Vector v)
        {
            return true;
        }

        Vector IProblem.RandomSolution()
        {
            Vector result = Vector.Random(dim, -30, 30);
            return result;
        }
    }
}
